package com.laolei.core.exception;

/**
 * 业务异常类.
 * 
 * @author Administrator
 *
 */
public class GlobalException extends RuntimeException {

	private static final long serialVersionUID = 1L;
	private int code;
	private String goUrl;
	private String describe;
	private String cnMsg;
	private String details;
	private ExceptionLevel level;

	private void init(ExceptionStatus exceptionstatus) {
		this.code = exceptionstatus.getCode();
		this.describe = exceptionstatus.getMessage();
		this.cnMsg = exceptionstatus.getCnmsg();
		this.goUrl = exceptionstatus.getGoUrl();
		this.level = exceptionstatus.getLevel();
	}

	@Override
	public String getMessage() {
		return new StringBuffer()
				.append("  异常级别:").append(this.level)
				.append("  异常代码:").append(this.code)
				.append("  中文描述:").append(this.cnMsg)
				.append("  英文描述:").append(this.describe)
				.append("  详细描述:").append(this.details)
				.append("  原始描述:").append(super.getMessage())
				.toString();
	}

	@Override
	public String toString() {
		return this.getMessage();
	}

	public GlobalException(final ExceptionStatus exceptionstatus) {
		this.init(exceptionstatus);
	}

	public final static void throwException(final ExceptionStatus exceptionstatus) {
		throw new GlobalException(exceptionstatus);
	}

	public GlobalException(final ExceptionStatus exceptionstatus, final Throwable throwable) {
		super(throwable);
		this.init(exceptionstatus);
	}

	public final static void throwException(final ExceptionStatus exceptionstatus, final Throwable throwable) {
		throw new GlobalException(exceptionstatus, throwable);
	}

	public GlobalException(final ExceptionStatus exceptionstatus, final Throwable throwable, final String details) {
		this(exceptionstatus, throwable);
		this.details = details;
	}

	public final static void throwException(final ExceptionStatus exceptionstatus, final Throwable throwable,
			final String details) {
		throw new GlobalException(exceptionstatus, throwable, details);
	}

	public GlobalException(final ExceptionStatus exceptionstatus, final String details) {
		this(exceptionstatus);
		this.details = details;
	}

	public final static void throwException(final ExceptionStatus exceptionstatus, final String details) {
		throw new GlobalException(exceptionstatus, details);
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getGoUrl() {
		return goUrl;
	}

	public void setGoUrl(String goUrl) {
		this.goUrl = goUrl;
	}

	public String getDescribe() {
		return describe;
	}

	public void setDescribe(String describe) {
		this.describe = describe;
	}

	public String getCnMsg() {
		return cnMsg;
	}

	public void setCnMsg(String cnMsg) {
		this.cnMsg = cnMsg;
	}

	public String getDetails() {
		return details;
	}

	public void setDetails(String details) {
		this.details = details;
	}

	public ExceptionLevel getLevel() {
		return level;
	}

	public void setLevel(ExceptionLevel level) {
		this.level = level;
	}

}
